﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Gencode.PrsCommon.Data.Dienst
{
	public class DienstSchema
	{
		public DataView Table
		{
			get;
			private set;
		}

		/// <summary>
		/// [dienstid,gerechnet,einsatzprotag,dienstname,kurztext,langtext,abteilungid,abteilungname]
		/// </summary>
		public DataView RawData
		{
			get;
			private set;
		}

		public DienstSchema(int schemaid, string mandid, int reservedcolumns, int dienstcolumncount)
		{
			RawData = DienstData.GetDienstSchema(schemaid, mandid);

			DataTable tbl = new DataTable();
			if (reservedcolumns > 1)
				tbl.Columns.Add("Abteilung");

			tbl.Columns.Add("Dienst");

			for (int i = 1; i <= dienstcolumncount; i++)
			{
				tbl.Columns.Add(i.ToString());
			}

			for (int i = 0; i < RawData.Count; i++)
			{
				DataRow row = tbl.NewRow();
				int index = 0;

				if (reservedcolumns > 1)
				{
					row[index] = RawData[i].Row["abteilungname"].ToString();
					index++;
				}
				row[index] = RawData[i].Row["dienstname"].ToString();
				index++;

				for (int c = 0; c < dienstcolumncount; c++)
				{
					row[c + index] = "-" + RawData[i].Row["einsatzprotag"].ToString();
				}
				tbl.Rows.Add(row);
			}

			Table = new DataView(tbl);
		}
	}
}
